package com.guo.core.framework.pro;

import cn.hutool.core.lang.Console;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import cn.hutool.http.HttpUtil;
import cn.hutool.http.Method;
import cn.hutool.json.JSONObject;
import org.junit.Test;

import java.sql.SQLException;
import java.util.List;

public class DriverQueueTest {

    String SQL = "-- 查询未完成的卸车排队\n" +
        "select\n" +
        "\tid,\n" +
        "\tcreate_time ,\n" +
        "\tdriver_mobile ,\n" +
        "\tcar_no ,\n" +
        "\twh_code ,\n" +
        "\tsite_code ,\n" +
        "\tcompany_code,\n" +
        "\tcode\n" +
        "from\n" +
        "\tmobile_driver_queue\n" +
        "where\n" +
        "\tdelete_flag = 0\n" +
        "\tand queue_type = 10\n" +
        "\tand create_time <= '2022-06-14 00:00:00'\n" +
//        "\tand create_time >= '2022-06-13 00:00:00'\n" +
        "\tand queue_status in (0, 10) limit 1000;";

    @Test
    public void cancelDriverQueue() throws SQLException, InterruptedException {
        String url = "http://10.18.45.99:19200/driverQueue";
        List<Entity> resultList = Db.use("ztb_prod").query(SQL);
        for (Entity entity : resultList) {
            JSONObject request = new JSONObject();
            request.put("id", entity.get("id"));
            request.put("code", entity.get("code"));
            request.put("whCode", entity.get("wh_code"));
            request.put("artificialFinish", 1);
            request.put("finish", "Y");
            request.put("flag", "0");
            request.put("queueType", 10);
            request.put("remark", "司机取消");
            String body = HttpUtil.createRequest(Method.PUT, url).body(request.toString()).execute().body();
            Thread.sleep(100);
            Console.log(body);
        }

    }

}
